package com.bdqn.demo.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class Util {
    private  static SqlSessionFactory sqlSessionFactory;
    static {
        InputStream inputStream = Util.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
    }

    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

    public static void clo(SqlSession sqlSession){
        sqlSession.close();
    }
}
